/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package univer;

import java.sql.*;


/**
 *
 * @author fairdev
 */
public class ConnManagerDao {

    private ConnManager connManager = null;

    public ConnManagerDao() throws Exception {

        connManager = new ConnManager();
    }

    public Department getDepartmentById(Integer id) throws Exception {

        Department dep = null;

        if (connManager != null) {
            Connection conn = connManager.getConnection();
            String sql = "SELECT * FROM Departments WHERE dep_id = ?";
            PreparedStatement stmt = conn.prepareStatement(sql);
            stmt.setInt(1, id);
            ResultSet rs = stmt.executeQuery();
            if (rs.next()) {
                dep = new Department();
                dep.setId(id);
                dep.setName(rs.getString("name"));
            }
        }

        return dep;
    }
}
